package com.winchain.provider.msg.service.impl;

import com.shell.bee.acct.transaction.dao.AcctTxWdrlDao;
import com.shell.framework.utils.SysDateUtil;
import com.winchain.chainbill.basic.activity.service.BasCusCpnService;
import com.winchain.chainbill.basic.activity.vo.BasCusCpnVo;
import com.winchain.chainbill.basic.cus.dao.CusGrpDao;
import com.winchain.chainbill.basic.cus.dao.CusRecDao;
import com.winchain.chainbill.basic.cus.po.CusGrp;
import com.winchain.chainbill.basic.invoice.dao.BasInvoiceDao;
import com.winchain.chainbill.basic.invoice.dao.InvoiceDeferedDao;
import com.winchain.chainbill.basic.invoice.po.BasInvoice;
import com.winchain.chainbill.basic.invoice.vo.BasInvoiceVo;
import com.winchain.chainbill.basic.invoice.vo.InvoiceDeferedVo;
import com.winchain.chainbill.bill.base.dao.CbDctDao;
import com.winchain.chainbill.bill.base.dao.CbRecDao;
import com.winchain.chainbill.bill.biz.discount.service.BillDctQueryService;
import com.winchain.chainbill.bill.biz.discount.vo.BillDct;
import com.winchain.chainbill.bill.biz.query.vo.CbRecQueryVo;
import com.winchain.chainbill.bill.biz.query.vo.CbRecVo;
import com.winchain.chainbill.receivables.base.dao.ArRecordDao;
import com.winchain.chainbill.receivables.biz.query.vo.ArRecordQueryVo;
import com.winchain.chainbill.serfee.service.ServiceFeeService;
import com.winchain.chainbill.tbill.base.dao.TbRecDao;
import com.winchain.chainbill.tbill.biz.service.TBillAprvService;
import com.winchain.chainbill.tbill.biz.service.TBillPayConfirmService;
import com.winchain.chainbill.tbill.biz.service.TBillPayInsService;
import com.winchain.chainbill.tbill.biz.service.TBillRevService;
import com.winchain.chainbill.tbill.biz.vo.TBillQueryVo;
import com.winchain.chainbill.tbill.biz.vo.TbRecVo;
import com.winchain.provider.msg.service.MsgTipService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("msgTipService")
public class MsgTipServiceImpl implements MsgTipService {
	@Autowired
	private CbRecDao cbRecDao;
	@Autowired
	ArRecordDao arRecordDao;
	@Autowired
	BillDctQueryService billDctQueryService;
	@Autowired
	private CusRecDao cusRecDao;
	@Autowired
	private CusGrpDao cusGrpDao;
	@Autowired
	private AcctTxWdrlDao acctTxWdrlDao;
	@Autowired
	private BasInvoiceDao basInvoiceDao;
	@Autowired
	private BasCusCpnService basCusCpnService;
	@Autowired
	private TBillPayInsService tBillPayInsService;
	@Autowired
	private TBillAprvService tBillAprvService;
	@Autowired
	private TBillPayConfirmService tBillPayConfirmService;
	@Autowired
	private ServiceFeeService serviceFeeService;
	@Autowired
	private CbDctDao cbDctDao;
	@Autowired
	private TbRecDao tbRecDao;
	@Autowired
	private InvoiceDeferedDao invoiceDeferedDao;
	@Autowired
	private TBillRevService tBillRevService;

	public int getMsgCountForSnd(String cusId, String billState) {
		return this.cbRecDao.getMsgTipBySnd(cusId, billState);
	}

	public int getMsgCountForRcv(String cusId, String billState) {
		return this.cbRecDao.getMsgTipByRcv(cusId, billState);
	}

	public int getMsgCountForRcvAprv(String cusId, String billState) {
		return this.cbRecDao.getMsgTipByRcvAprv(cusId, billState);
	}

	public int getMsgCountForXfe(String cusId, String billState) {
		return this.cbRecDao.getMsgTipByXfe(cusId, billState);
	}

	public int getMsgCountForDct(String cusId, String billState) {
		return this.cbRecDao.getMsgTipByDct(cusId, billState);
	}

	public int getMsgCountForReceivable(String cusId, String arState) {
		ArRecordQueryVo arRecord = new ArRecordQueryVo();
		arRecord.setBuyerId(cusId);
		String[] arStates = { arState };
		arRecord.setArStates(arStates);
		return this.arRecordDao.selectRecords(arRecord).size();
	}

	public int getMsgCountForDctPay(String cusId) {
		int count = 0;
		CbRecQueryVo cbRecordQueryVo = new CbRecQueryVo();
		List<BillDct> list = this.billDctQueryService.selectDctBillForPaid(cbRecordQueryVo, cusId);
		if (list != null) {
			count = list.size();
		}
		return count;
	}

	public int getMsgCountForRpurPmt(String cusId) {
		int count = 0;
		CbRecQueryVo recordQueryVo = new CbRecQueryVo();
		recordQueryVo.setFinId(cusId);
		String[] billStates = { "S014", "S031" };

		recordQueryVo.setBillStates(billStates);
		List<CbRecVo> bills = this.cbRecDao.selectBillForRpurPaid(recordQueryVo);
		if (bills != null) {
			count = bills.size();
		}
		return count;
	}

	public int getMsgCountForTrial(String cusId, String... cusState) {
		return this.cusRecDao.countMsgForTrial(cusId, cusState);
	}

	public int getMsgCountForWithdraw(String cusId) {
		List<CusGrp> grps = this.cusGrpDao.selectCusGroupByTagCode(cusId, new String[] { "GROUP_ADMIN" });
		if ((grps == null) || (grps.size() == 0)) {
			return 0;
		}
		List<String> grpIdList = new ArrayList();
		for (CusGrp grp : grps) {
			grpIdList.add(grp.getGrpId());
		}
		Object list = this.acctTxWdrlDao.getWithdrawList(null, "1",

				(String[]) grpIdList.toArray(new String[0]), null, null);
		return ((List) list).size();
	}

	public int getMsgCountForInvoiceMgt(String cusId, String invoiceType) {
		BasInvoiceVo basInvoiceVo = new BasInvoiceVo();
		basInvoiceVo.setFinId(cusId);
		basInvoiceVo.setInvoiceState("0");
		basInvoiceVo.setInvoiceType(invoiceType);
		List<BasInvoice> list = this.basInvoiceDao.selectBasInvoicesForMgtByPage(basInvoiceVo);
		int count = 0;
		if (list != null) {
			count = list.size();
		}
		return count;
	}

	public int getMsgCountForDctPrePay(String cusId) {
		int count = 0;
		CbRecQueryVo cbRecordQueryVo = new CbRecQueryVo();
		List<BillDct> list = this.billDctQueryService.selectDctBillForPrePaid(cbRecordQueryVo, cusId);
		if (list != null) {
			count = list.size();
		}
		return count;
	}

	public int getActivityCusCoupon(String cusId) {
		BasCusCpnVo basCusCpnVo = new BasCusCpnVo();
		basCusCpnVo.setCusId(cusId);
		basCusCpnVo.setCpnSts("1");
		List<BasCusCpnVo> list = this.basCusCpnService.selectCusCpns(basCusCpnVo);
		return list != null ? list.size() : 0;
	}

	public int getMsgCountForTBillPayIns(String cusId) {
		return this.tBillPayInsService.getMsgCountForTBillPayIns(cusId);
	}

	public int getMsgCountForTBillAprv(String cusId) {
		return this.tBillAprvService.getMsgCountForTBillAprv(cusId);
	}

	public int getMsgCountForServiceFee(String cusId) {
		return this.serviceFeeService.getMsgCountForServiceFee(cusId);
	}

	public int getMsgCountForTBillPayConfirm(String cusId) {
		return this.tBillPayConfirmService.getMsgCountForTBillPayConfirm(cusId);
	}

	public int getMsgCountForBillDctApprove(String cusId) {
		CbRecQueryVo vo = new CbRecQueryVo();
		vo.setFinId(cusId);
		vo.setDctDate(SysDateUtil.getSystemDate());
		List<BillDct> list = this.cbDctDao.selectDctBillForApprove(vo);
		return list != null ? list.size() : 0;
	}

	public int getCountForBillDctUnuploadInvoice(String cusId) {
		CbRecQueryVo vo = new CbRecQueryVo();
		vo.setSellerId(cusId);
		List<BillDct> list = this.cbDctDao.selectUnuploadInvoiceList(vo);
		return list != null ? list.size() : 0;
	}

	public int getCountForTBillDctUnuploadInvoice(String cusId) {
		TBillQueryVo vo = new TBillQueryVo();
		vo.setCusId(cusId);
		List<TbRecVo> list = this.tbRecDao.selectUnuploadInvoiceList(vo);
		return list != null ? list.size() : 0;
	}

	public int getMsgCountForInvoiceAprv(String cusId) {
		InvoiceDeferedVo invoiceDeferedVo = new InvoiceDeferedVo();
		invoiceDeferedVo.setFinId(cusId);
		List<InvoiceDeferedVo> list = this.invoiceDeferedDao.selectBasInvoicesForMgtByPage(invoiceDeferedVo);
		return list != null ? list.size() : 0;
	}

	public int getMsgCountForTBillRev(String cusId) {
		return this.tBillRevService.getMsgCountForTBillRev(cusId);
	}
}
